//
//  AbsenceViewController.m
//  掌上海印
//
//  Created by admin on 16/4/16.
//  Copyright © 2016年 handsome. All rights reserved.
//

#import "AbsenceViewController.h"
#import "Util.h"
@interface AbsenceViewController ()<UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>

@end

@implementation AbsenceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"请假";
    self.tabBarController.tabBar.hidden = YES;
    self.view.backgroundColor = bgColor;
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
//    self.time.resignFirstResponder = YES;
    [self.time resignFirstResponder];
    [self.reason resignFirstResponder];
    
}

- (IBAction)addImage:(id)sender {
    [self getPhoto];
}

- (IBAction)sendAbsence:(id)sender {
    [Util toastWithView:self.view.window AndText:@"请假条已发送~"];
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 打开photo
- (void)getPhoto{

    UIActionSheet *myActionSheet = [[UIActionSheet alloc]
                                    initWithTitle:nil
                                    delegate:self
                                    cancelButtonTitle:@"取消"
                                    destructiveButtonTitle:nil
                                    otherButtonTitles:@"从相册中选择" , @"拍照",nil];
    [myActionSheet showInView:self.view];
    
}

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            //从相册选择
            [self LocalPhoto];
            break;
        case 1:
            //拍照
            [self takePhoto];
            break;
        default:
            break;
    }
}


//从相册选择
-(void)LocalPhoto{
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    //资源类型为图片库
    picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    picker.delegate = self;
    //设置选择后的图片可被编辑
    //    picker.allowsEditing = YES;
    [self presentViewController:picker animated:YES completion:^{
    } ];
}

//拍照
-(void)takePhoto{
    //资源类型为照相机
    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
    //判断是否有相机
    if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate = self;
        //设置拍照后的图片可被编辑
        picker.allowsEditing = YES;
        //资源类型为照相机
        picker.sourceType = sourceType;
        [self presentViewController:picker animated:YES completion:^{
            
        } ];
    }
}


#pragma Delegate method UIImagePickerControllerDelegate
//图像选取器的委托方法，选完图片后回调该方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
    _imageView.image = image;

    
    //关闭相册界面
    [picker dismissModalViewControllerAnimated:YES];
}


@end
